package com.hhx.androidrxmvp.base;

import android.os.Bundle;

import com.hhx.androidrxmvp.app.BaseApplication;
import com.hhx.androidrxmvp.base.mvp.BasePresenter;
import com.hhx.androidrxmvp.dagger.component.DaggerFragmentComponent;
import com.hhx.androidrxmvp.dagger.component.FragmentComponent;

import javax.inject.Inject;

/**
 * @author ddnosh
 * @website http://blog.csdn.net/ddnosh
 */
public abstract class BaseMvpFragment<P extends BasePresenter> extends SimpleFragment {

    @Inject
    public P mPresenter;
    protected String TAG = "BaseMvpFragment";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //dagger2
        initInjector();
        if (mPresenter != null) {
            mPresenter.attachView(this);
        }
    }

    @Override
    public void onDestroy() {
        if (mPresenter != null) {
            mPresenter.detachView();
            mPresenter = null;
        }
        super.onDestroy();
    }

    protected void initInjector() {

    }

    protected FragmentComponent getFragmentComponent() {
        return DaggerFragmentComponent.builder()
                .applicationComponent(BaseApplication.getApplicationComponent())
                // .fragmentModule(getFragmentModule())
                .build();
    }

  /*  protected FragmentModule getFragmentModule() {
        return new FragmentModule(this);
    }*/

}
